package GUI;

import javax.swing.JPanel;
import java.awt.SystemColor;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import Client.BusinessImplements;
import Controler.*;
import java.awt.Color;
import javax.swing.border.LineBorder;
/**
  * @author Lucie
 * Class name Create_NewMember_panel
 * extend  Abstract_Jpanel
 * purpose: this panel get details of member from the user and call the controller 
 * to add new member to the data base
 */
public class Create_NewMember_panel extends Abstract_Jpanel { 
	private JTextField textname;
	private JTextField textphone;
	private JTextField textlastname;
	private JTextField textid;
	private JTextField textemail;
	private Create_memmber_card_controler memmber_card_controler;
	public JButton btnBack ;
	
	/**
	 * Create the panel.
	 */
	public Create_NewMember_panel() {
		setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBorder(new LineBorder(SystemColor.activeCaption, 6));
		panel.setBackground(SystemColor.inactiveCaption);
		panel.setBounds(36, 55, 709, 369);
		add(panel);
		panel.setLayout(null);
		btnBack = new JButton("back");
		btnBack.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new LineBorder(SystemColor.control, 6));
		panel_1.setBackground(new Color(220, 220, 220));
		panel_1.setBounds(107, 36, 482, 294);
		panel.add(panel_1);
		panel_1.setLayout(null);
		
		JLabel lblName = new JLabel("name:");
		lblName.setBounds(41, 11, 67, 25);
		panel_1.add(lblName);
		lblName.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		textname = new JTextField();
		textname.setBounds(152, 15, 158, 20);
		panel_1.add(textname);
		textname.setColumns(10);
		
		textlastname = new JTextField();
		textlastname.setBounds(152, 68, 158, 20);
		panel_1.add(textlastname);
		textlastname.setColumns(10);
		
		JLabel lblLastName = new JLabel("last name:");
		lblLastName.setBounds(41, 62, 67, 29);
		panel_1.add(lblLastName);
		lblLastName.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		textid = new JTextField();
		textid.setBounds(152, 120, 158, 20);
		panel_1.add(textid);
		textid.setColumns(10);
		
		JLabel lblId = new JLabel("id:");
		lblId.setBounds(41, 121, 52, 14);
		panel_1.add(lblId);
		lblId.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		textphone = new JTextField();
		textphone.setBounds(152, 175, 158, 20);
		panel_1.add(textphone);
		textphone.setColumns(10);
		
		JLabel lblPhoneNumber = new JLabel("phone number:");
		lblPhoneNumber.setBounds(41, 171, 96, 25);
		panel_1.add(lblPhoneNumber);
		lblPhoneNumber.setFont(new Font("Tahoma", Font.PLAIN, 14));
		
		textemail = new JTextField();
		textemail.setBounds(152, 231, 158, 20);
		panel_1.add(textemail);
		textemail.setColumns(10);
		
		JLabel lblEmailAddress = new JLabel("email:");
		lblEmailAddress.setBounds(41, 227, 67, 25);
		panel_1.add(lblEmailAddress);
		lblEmailAddress.setFont(new Font("Tahoma", Font.PLAIN, 14));
		/*
		 *btnCreate=When you click this button you will call set_new_member_data(id(),name, last name, phone,mail,status)
		 * a method of the controller of this panel if this method return true we will
		 * call the methods of this class next_screen_success(),empty_text_fields();
		 * else we call next_screen_faild(memmber_card_controler.get_msg());	
		 * 	memmber_card_controler.get_msg(); return the msg from the controller with all
		 * the error msg.
		 */
		JButton btnCreate = new JButton("create");
		btnCreate.setFont(new Font("Tahoma", Font.PLAIN, 14));
		btnCreate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				 memmber_card_controler=new Create_memmber_card_controler();
				 
					if(memmber_card_controler.set_new_member_data(get_id(),getname(),  getlastname(), getphone(), get_mail(),get_status()))
					{
						next_screen_success();
						empty_text_fields();
						
					}
					else {
						next_screen_faild(memmber_card_controler.get_msg());
						
					}
				
			}
		});
		btnCreate.setBounds(621, 435, 96, 33);
		add(btnCreate);
		
		//btnBack ;When you click this button you will return to 
				//sing in panel screen
		btnBack.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Sign_in_panel sip=new Sign_in_panel();
				on_screen_unload();
				BusinessImplements.GetInstance().getMainFrame().setContentPane(sip);
				sip.setSize(getMaximumSize());
				sip.on_screen_load();
				
				
			}
		});
		btnBack.setBounds(41, 435, 96, 33);
		add(btnBack);
		
		JLabel lblCreatNewMemmber = new JLabel("Create New Memmber");
		lblCreatNewMemmber.setForeground(new Color(25, 25, 112));
		lblCreatNewMemmber.setFont(new Font("MV Boli", Font.BOLD, 30));
		lblCreatNewMemmber.setBounds(47, 11, 414, 28);
		add(lblCreatNewMemmber);

	}

	@Override
	public void next_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void prev_screen() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_load() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void on_screen_unload() {
		// TODO Auto-generated method stub
		
	}
	

	/**
	 * 
	 * @return name of member that the user enter in "textname"
	 */
	public String getname()
	{
		return textname.getText();
	}
	/**
	 * 
	 * @return  phone of member that the user enter in "textphone"
	 */
	public String getphone()
	{
		return textphone.getText();
	}
	/**
	 * 
	 * @return  last name of member that the user enter in "textlastname"
	 */
	public String getlastname()
	{
		return textlastname.getText();
	}
	/**
	 * 
	 * @return id of member that the user enter in "textid"
	 */
	public String get_id()
	{
		return textid.getText();
		
			
	}
	/**
	 * 
	 * @return mail of member that the user enter in "textemail"
	 */
	public String get_mail()
	{
		return textemail.getText();
	}
	
	/**
	 * 
	 * @return status="0" (active status)
	 */
	
	public String get_status()
	{

			return "0";
			
	}


	/**
	 * this method display showMessageDialog with a success msg
	 */
	public void next_screen_success()
	{
		JOptionPane.showMessageDialog(this,"apply success");
	}
	
	/**
	 * this method display showMessageDialog with a failed msg
	 * @param msg
	 */
	public void next_screen_faild(String msg)
	{
		JOptionPane.showMessageDialog(this,"apply faild "+msg);
	}
	
	
	/**
	 * this method empty all the text field
	 */
	public void empty_text_fields()
	{
		textname.setText(null);
		textphone.setText(null);
		textlastname.setText(null);
		textid.setText(null);
		textemail.setText(null);
	
		
	}
}
